<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('product:productDetails:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.productId" placeholder="产品附加属性" clearable></el-input>
          <el-input v-model="search.commentCount" placeholder="客户评论 总数量" clearable></el-input>
          <el-input v-model="search.commentHp" placeholder="好评率1-100" clearable></el-input>
          <el-input v-model="search.commentHpsl" placeholder="好评数量" clearable></el-input>
          <el-input v-model="search.commentZcsl" placeholder="中差评数量" clearable></el-input>
          <el-input v-model="search.commentXjzl" placeholder="总星数量" clearable></el-input>
          <el-input v-model="search.lookCount" placeholder="浏览人数" clearable></el-input>
          <el-input v-model="search.collectionCount" placeholder="收藏人数" clearable></el-input>
          <el-input v-model="search.tagCount" placeholder="称赞人数" clearable></el-input>
          <el-input v-model="search.saleCount" placeholder="销售数量" clearable></el-input>
          <el-input v-model="search.stockQty" placeholder="库存数量 -9不限库存" clearable></el-input>
          <el-input v-model="search.logisWeight" placeholder="物流重量(Kg)" clearable></el-input>
          <el-input v-model="search.logisVolume" placeholder="物流体积(m3)" clearable></el-input>
          <el-input v-model="search.logisModelId" placeholder="快递模板公司 0包邮 <0系统模板id的负数" clearable></el-input>
          <el-input v-model="search.providerId" placeholder="供应商id" clearable></el-input>
          <el-input v-model="search.templatePath" placeholder="产品页面模板" clearable></el-input>
          <el-input v-model="search.createTime" placeholder="创建时间" clearable></el-input>
          <el-input v-model="search.publishTime" placeholder="发布时间" clearable></el-input>
          <el-input v-model="search.planEndTime" placeholder="计划下架时间" clearable></el-input>
          <el-input v-model="search.planStartTime" placeholder="计划上架时间" clearable></el-input>
          <el-input v-model="search.invoice" placeholder="有无发票 1有 0无" clearable></el-input>
          <el-input v-model="search.guarantee" placeholder="有无保修 1有 0无" clearable></el-input>
          <el-input v-model="search.linkMan" placeholder="联系人" clearable></el-input>
          <el-input v-model="search.linkTel" placeholder="联系电话" clearable></el-input>
          <el-input v-model="search.linkAddress" placeholder="联系地址" clearable></el-input>
          <el-input v-model="search.longitude" placeholder="经度" clearable></el-input>
          <el-input v-model="search.latitude" placeholder="纬度" clearable></el-input>
          <el-input v-model="search.deleted" placeholder="逻辑删除" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="productDetailsId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="产品附加属性" prop="productId" width="150"></el-table-column>
        <el-table-column label="客户评论 总数量" prop="commentCount" width="150"></el-table-column>
        <el-table-column label="好评率1-100" prop="commentHp" width="150"></el-table-column>
        <el-table-column label="好评数量" prop="commentHpsl" width="150"></el-table-column>
        <el-table-column label="中差评数量" prop="commentZcsl" width="150"></el-table-column>
        <el-table-column label="总星数量" prop="commentXjzl" width="150"></el-table-column>
        <el-table-column label="浏览人数" prop="lookCount" width="150"></el-table-column>
        <el-table-column label="收藏人数" prop="collectionCount" width="150"></el-table-column>
        <el-table-column label="称赞人数" prop="tagCount" width="150"></el-table-column>
        <el-table-column label="销售数量" prop="saleCount" width="150"></el-table-column>
        <el-table-column label="库存数量 -9不限库存" prop="stockQty" width="150"></el-table-column>
        <el-table-column label="物流重量(Kg)" prop="logisWeight" width="150"></el-table-column>
        <el-table-column label="物流体积(m3)" prop="logisVolume" width="150"></el-table-column>
        <el-table-column label="快递模板公司 0包邮 <0系统模板id的负数" prop="logisModelId" width="150"></el-table-column>
        <el-table-column label="供应商id" prop="providerId" width="150"></el-table-column>
        <el-table-column label="产品页面模板" prop="templatePath" width="150"></el-table-column>
        <el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
        <el-table-column label="发布时间" prop="publishTime" width="150"></el-table-column>
        <el-table-column label="计划下架时间" prop="planEndTime" width="150"></el-table-column>
        <el-table-column label="计划上架时间" prop="planStartTime" width="150"></el-table-column>
        <el-table-column label="有无发票 1有 0无" prop="invoice" width="150"></el-table-column>
        <el-table-column label="有无保修 1有 0无" prop="guarantee" width="150"></el-table-column>
        <el-table-column label="联系人" prop="linkMan" width="150"></el-table-column>
        <el-table-column label="联系电话" prop="linkTel" width="150"></el-table-column>
        <el-table-column label="联系地址" prop="linkAddress" width="150"></el-table-column>
        <el-table-column label="经度" prop="longitude" width="150"></el-table-column>
        <el-table-column label="纬度" prop="latitude" width="150"></el-table-column>
        <el-table-column label="逻辑删除" prop="deleted" width="150"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('product:productDetails:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('product:productDetails:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <productDetailsEdit-dialog v-if="dialog.productDetailsEdit" ref="productDetailsEditDialog" @success="handleSaveSuccess" @closed="dialog.productDetailsEdit=false"></productDetailsEdit-dialog>
</template>

<script>
  import productAPI from '@/api/product/productDetails';
  import productDetailsEditDialog from './productDetailsEdit';//1--导入
  export default {
    name: 'productDetails',
    components: {
        productDetailsEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          productDetailsEdit: false
        },
        apiObj: productAPI.productDetails.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        }
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.productDetailsEdit = true
        this.$nextTick(() => {
          this.$refs.productDetailsEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.productDetailsEdit = true
        this.$nextTick(() => {
          this.$refs.productDetailsEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await productAPI.productDetails.delete.delete(row.productDetailsId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
    }
  }
</script>
<style>
</style>
